﻿using B.S.BasicData.Api.Read.Application.Command.Menu;
using B.S.BasicData.Api.Read.DTO;
using B.S.BasicData.Domian.Entities.Menu;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interface;
using MediatR;

namespace B.S.BasicData.Api.Read.Application.Handler.Menu
{
    public class GetZiHandler : IRequestHandler<GetZiCommand, ApiResult<List<GetMenuDTO>>>
    {
        private readonly IBaseRepository<MenuModel> menuRepo;

        public GetZiHandler(IBaseRepository<MenuModel>menuRepo)
        {
            this.menuRepo = menuRepo;
        }
        public Task<ApiResult<List<GetMenuDTO>>> Handle(GetZiCommand request, CancellationToken cancellationToken)
        {
            var res=new ApiResult<List<GetMenuDTO>>();
            var info = menuRepo.GetAll().Where(x => x.Pid == request.Id);
            if(info.Count() > 0)
            {
                res.Message = "有子集";
                res.Code = ApiEnum.Ok;
            }
            else
            {
                res.Message = "没有子集";
                res.Code = ApiEnum.File;
            }
            return Task.FromResult(res);
        }
    }
}
